home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / tests / pdevtest / RCS / pdevtest.c,v < prev    next >
Encoding:
Text File  |  1989-10-23  |  11.5 KB  |  516 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    jhh:1.3; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.3
  10. date     89.10.22.22.03.13;  author jhh;  state Exp;
  11. branches ;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     88.08.26.16.24.30;  author brent;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     88.04.16.12.27.57;  author brent;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @Top level routine for pseudo-device benchmark
  27. @
  28.  
  29.  
  30. 1.3
  31. log
  32. @checking in Brent's changes
  33. @
  34. text
  35. @/*
  36.  * Test driver for the pseudo-device implementation.
  37.  *
  38.  * The programs output goes to standard out, while the
  39.  * statistics taken go to error output or another file.
  40.  */
  41.  
  42. #include <sprite.h>
  43. #include <status.h>
  44. #include <stdio.h>
  45. #include <fs.h>
  46. #include <fsCmd.h>
  47. #include <sysStats.h>
  48. #include <rpc.h>
  49. #include <proc.h>
  50. #include <vm.h>
  51. #include <kernel/sched.h>
  52. #include <kernel/fsStat.h>
  53. #include <kernel/vm.h>
  54. #include <option.h>
  55. #include "pdevInt.h"
  56.  
  57. Boolean clean = FALSE;
  58. Boolean histogram = FALSE;
  59. Boolean useSelect = FALSE;
  60. Boolean copy = FALSE;
  61. Boolean readP = FALSE;
  62. Boolean writeP = FALSE;
  63. Boolean ioctlP = FALSE;
  64. Boolean selectP = FALSE;
  65. Boolean switchBuf = FALSE;
  66. Boolean writeBehind = FALSE;
  67. int size = 128;
  68. int reps = 100;
  69. int numClients = -1;            /* For multi-program synchronization,
  70.                      * this is the number of slaves with
  71.                      * which to synchronize */
  72. int delay = 0;                /* Delay loop for server to eat CPU */
  73. Boolean slave = FALSE;
  74. char outFileDefault[] = "pdevtest.out";
  75. char *outFile = outFileDefault;
  76.  
  77. Option optionArray[] = {
  78.     {OPT_INT, "M", (Address)&numClients,
  79.         "Master for -M (int) clients"},
  80.     {OPT_TRUE, "S", (Address)&slave,
  81.         "Slave bench program\nTests:"},
  82.     {OPT_STRING, "o", (Address)&outFile,
  83.         "Output file name"},
  84.     {OPT_STRING, "p", (Address)&pdev,
  85.         "Name of the master pseudo device"},
  86.     {OPT_TRUE, "i", (Address)&ioctlP,
  87.         "IOControl test"},
  88.     {OPT_TRUE, "r", (Address)&readP,
  89.         "Read test"},
  90.     {OPT_TRUE, "w", (Address)&writeP,
  91.         "Write test"},
  92.     {OPT_TRUE, "W", (Address)&writeBehind,
  93.         "Enable write behind (with -M)"},
  94.     {OPT_TRUE, "s", (Address)&selectP,
  95.         "Select, makes master block client"},
  96.     {OPT_TRUE, "c", (Address)©,
  97.         "Copy stream test, the slave forks"},
  98.     {OPT_INT, "n", (Address)&reps,
  99.         "Number of repetitions"},
  100.     {OPT_INT, "d", (Address)&size,
  101.         "Amount of data to transfer"},
  102.     {OPT_INT, "P", (Address)&delay,
  103.         "Loop for -P <int> cylces before replying"},
  104.     {OPT_TRUE, "z", (Address)&useSelect,
  105.         "Force Master to use select with 1 client"},
  106.     {OPT_TRUE, "b", (Address)&switchBuf,
  107.         "Test switching request buffers (use with -i)\nTracing:"},
  108.     {OPT_TRUE, "x", (Address)&clean,
  109.         "Turn off all tracing"},
  110.     {OPT_TRUE, "h", (Address)&histogram,
  111.         "Leave histograms on (ok with -x)"},
  112. };
  113. int numOptions = sizeof(optionArray) / sizeof(Option);
  114.  
  115. FsStats fsStartStats, fsEndStats;
  116. Vm_Stat    vmStartStats, vmEndStats;
  117. Time startTime, endTime;
  118. Sched_Instrument startSchedStats, endSchedStats;
  119.  
  120. main(argc, argv)
  121.     int argc;
  122.     char *argv[];
  123. {
  124.     register ReturnStatus status = SUCCESS;
  125.     Proc_PID child;
  126.     Proc_ResUsage usage;
  127.     FILE * outStream;
  128.     register int i;
  129.     ClientData serverData, clientData;
  130.  
  131.     argc = Opt_Parse(argc, argv, optionArray, numOptions, OPT_ALLOW_CLUSTERING);
  132.     if (!slave && (numClients < 0)) {
  133.     fprintf(stderr, "Master: %s [-xfpoh] -M numSlaves\n",
  134.                 argv[0]);
  135.     fprintf(stderr, "Slave: %s [-xfpoh] -S\n", argv[0]);
  136.     Opt_PrintUsage(argv[0], optionArray, numOptions);
  137.     exit(1);
  138.     }
  139.     if (size > MAX_SIZE) {
  140.     size = MAX_SIZE;
  141.     }
  142.     if (clean) {
  143.     int newValue;
  144.     newValue = 0;
  145.     Fs_Command(FS_SET_CACHE_DEBUG, sizeof(int), &newValue);
  146.     newValue = 0;
  147.     Fs_Command(FS_SET_TRACING, sizeof(int), &newValue);
  148.     newValue = 0;
  149.     Fs_Command(FS_SET_RPC_DEBUG, sizeof(int), &newValue);
  150.     newValue = 0;
  151.     Fs_Command(FS_SET_RPC_TRACING, sizeof(int), &newValue);
  152.     if (!histogram) {
  153.         newValue = 0;
  154.         (void) Fs_Command(FS_SET_RPC_SERVER_HIST, sizeof(int), &newValue);
  155.         newValue = 0;
  156.         (void) Fs_Command(FS_SET_RPC_CLIENT_HIST, sizeof(int), &newValue);
  157.     }
  158.     }
  159.     outStream = fopen(outFile, "w+");
  160.     if (outStream == (FILE *)NULL) {
  161.     perror(outFile);
  162.     exit(status);
  163.     }
  164.     /*
  165.      * Copy command line to output file.
  166.      */
  167.     fprintf(outStream, "%s ", argv[0]);
  168.     if (clean) {
  169.     fprintf(outStream, "-x ");
  170.     }
  171.     if (histogram) {
  172.     fprintf(outStream, "-h ");
  173.     }
  174.     if (clean) {
  175.     fprintf(outStream, "-x ");
  176.     }
  177.     for (i=1 ; i<argc ; i++) {
  178.     fprintf(outStream, "%s ", argv[i]);
  179.     }
  180.     fprintf(outStream, "\n");
  181.     /*
  182.      * Check for multi-program master/slave setup.
  183.      */
  184.     if (numClients > 0) {
  185.     ServerSetup(numClients, &serverData);
  186.     slave = FALSE;
  187.     }
  188.     if (slave) {
  189.     ClientSetup(&clientData);
  190.     }
  191.     /*
  192.      * Get first sample of filesystem stats, vm stats, time, and idle ticks.
  193.      */
  194.     status = Fs_Command(FS_RETURN_STATS, sizeof(FsStats), &fsStartStats);
  195.     if (status != SUCCESS) {
  196.     Stat_PrintMsg(status, "Error getting FS stats");
  197.     exit(status);
  198.     }
  199.     status = Vm_Cmd(VM_GET_STATS, &vmStartStats);
  200.     if (status != SUCCESS) {
  201.     Stat_PrintMsg(status, "Error getting VM stats");
  202.     exit(status);
  203.     }
  204.     status = Sys_Stats(SYS_SCHED_STATS, 0, &startSchedStats);
  205.     if (status != SUCCESS) {
  206.     Stat_PrintMsg(status, "Error in Sys_Stats");
  207.     exit(status);
  208.     }
  209.  
  210.     status = Sys_GetTimeOfDay(&startTime, NULL, NULL);
  211.     if (status != SUCCESS) {
  212.     Stat_PrintMsg(status, "Error in Sys_GetTimeOfDay");
  213.     exit(status);
  214.     }
  215.     if (slave) {
  216.     if (copy) {
  217.         child = fork();
  218.     }
  219.     if (readP) {
  220.         ClientRead(clientData, size, reps);
  221.     }
  222.     if (writeP) {
  223.         ClientWrite(clientData, size, reps);
  224.     }
  225.     if (ioctlP) {
  226.         ClientIOControl(clientData, size, reps);
  227.     }
  228.     if (copy) {
  229.         if (child != 0) {
  230.         (void)wait(0);
  231.         } else {
  232.         exit(0);
  233.         }
  234.     }
  235.     /*
  236.      * Take ending statistics and print user, system, and elapsed times.
  237.      */
  238.     Sys_GetTimeOfDay(&endTime, NULL, NULL);
  239.     Sys_Stats(SYS_SCHED_STATS, 0, &endSchedStats);
  240.     Time_Subtract(endTime, startTime, &endTime);
  241.     printf("Slave: ");
  242.     PrintTimes(stdout, &usage, &endTime);
  243.  
  244.     Sys_Shutdown(0);    /* sync cache */
  245.     ClientDone(clientData);
  246.  
  247.     Fs_Command(FS_RETURN_STATS, sizeof(FsStats), &fsEndStats);
  248.     Vm_Cmd(VM_GET_STATS, &vmEndStats);
  249.     /*
  250.      * Print FS statistics.
  251.      */
  252.     fprintf(outStream, "C: ");
  253.     PrintIdleTime(outStream, &startSchedStats, &endSchedStats, &endTime);
  254.     PrintFsStats(outStream, &fsStartStats, &fsEndStats);
  255.     /*
  256.      * Print VM statistics.
  257.      */
  258.     PrintVmStats(outStream, &vmStartStats, &vmEndStats);
  259.     } else {
  260.     /*
  261.      * Drop into the top level service loop.  ServeOne is a faster
  262.      * version that doesn't use select because there is only
  263.      * one client.
  264.      */
  265.     if (numClients > 1 || useSelect) {
  266.         Serve(serverData);
  267.     } else {
  268.         ServeOne(serverData);
  269.     }
  270.     /*
  271.      * Take ending statistics and print user, system, and elapsed times.
  272.      */
  273.     Sys_GetTimeOfDay(&endTime, NULL, NULL);
  274.     Sys_Stats(SYS_SCHED_STATS, 0, &endSchedStats);
  275.     Time_Subtract(endTime, startTime, &endTime);
  276.     printf("Master: ");
  277.     PrintTimes(stdout, &usage, &endTime);
  278.  
  279.     Sys_Shutdown(0);    /* sync cache */
  280.     Fs_Command(FS_RETURN_STATS, sizeof(FsStats), &fsEndStats);
  281.     Vm_Cmd(VM_GET_STATS, &vmEndStats);
  282.     /*
  283.      * Print FS statistics.
  284.      */
  285.     fprintf(outStream, "S: ");
  286.     PrintIdleTime(outStream, &startSchedStats, &endSchedStats, &endTime);
  287.     PrintFsStats(outStream, &fsStartStats, &fsEndStats);
  288.     /*
  289.      * Print VM statitistics.
  290.      */
  291.     PrintVmStats(outStream, &vmStartStats, &vmEndStats);
  292.  
  293.     if (delay > 0) {
  294.         int cnt;
  295.         Sys_GetTimeOfDay(&startTime, NULL, NULL);
  296.         for (cnt=0 ; cnt<50 ; cnt++) {
  297.         for (i=delay<<1 ; i>0 ; i--) ;
  298.         }
  299.         Sys_GetTimeOfDay(&endTime, NULL, NULL);
  300.         Time_Subtract(endTime, startTime, &endTime);
  301.         Time_Divide(endTime, 50, &endTime);
  302.         printf("%d.%06d seconds service delay\n",
  303.         endTime.seconds, endTime.microseconds);
  304.     }
  305.     }
  306.     exit(status);
  307. }
  308. @
  309.  
  310.  
  311. 1.2
  312. log
  313. @Added service delay
  314. @
  315. text
  316. @d2 1
  317. a2 1
  318.  * Driver for the new (Dec 87) pseudo-device implementation.
  319. d8 14
  320. a21 13
  321. #include "sprite.h"
  322. #include "status.h"
  323. #include "io.h"
  324. #include "fs.h"
  325. #include "fsCmd.h"
  326. #include "sysStats.h"
  327. #include "rpc.h"
  328. #include "proc.h"
  329. #include "vm.h"
  330. #include "kernel/sched.h"
  331. #include "kernel/fsStat.h"
  332. #include "kernel/vm.h"
  333. #include "option.h"
  334. a22 1
  335. Boolean flushCache = FALSE;
  336. d27 4
  337. a30 4
  338. Boolean read = FALSE;
  339. Boolean write = FALSE;
  340. Boolean ioctl = FALSE;
  341. Boolean select = FALSE;
  342. d34 1
  343. a34 1
  344. int reps = 10;
  345. d40 2
  346. a41 2
  347. char *outFile = "pdevtest.out";
  348. extern char *pdev;
  349. d44 1
  350. a44 1
  351.     {OPT_INT, 'M', (Address)&numClients,
  352. d46 1
  353. a46 1
  354.     {OPT_TRUE, 'S', (Address)&slave,
  355. d48 7
  356. a54 9
  357.     {OPT_INT, 'n', (Address)&reps,
  358.         "Number of repetitions"},
  359.     {OPT_INT, 'd', (Address)&size,
  360.         "Amount of data to transfer"},
  361.     {OPT_TRUE, 's', (Address)&select,
  362.         "Select, makes master block client"},
  363.     {OPT_TRUE, 'c', (Address)©,
  364.         "Copy stream test, the slave forks"},
  365.     {OPT_TRUE, 'r', (Address)&read,
  366. d56 1
  367. a56 1
  368.     {OPT_TRUE, 'w', (Address)&write,
  369. d58 1
  370. a58 1
  371.     {OPT_TRUE, 'W', (Address)&writeBehind,
  372. d60 9
  373. a68 3
  374.     {OPT_TRUE, 'i', (Address)&ioctl,
  375.         "IOControl test"},
  376.     {OPT_INT, 'P', (Address)&delay,
  377. d70 5
  378. a74 9
  379.     {OPT_TRUE, 'b', (Address)&switchBuf,
  380.         "Test switching request buffers (use with -i)"},
  381.     {OPT_STRING, 'o', (Address)&outFile,
  382.         "Output file name\n"},
  383.     {OPT_STRING, 'p', (Address)&pdev,
  384.         "Name of the master pseudo device\nTracing:"},
  385.     {OPT_TRUE, 'f', (Address)&flushCache,
  386.         "Flush cache before benchmark"},
  387.     {OPT_TRUE, 'x', (Address)&clean,
  388. d76 1
  389. a76 1
  390.     {OPT_TRUE, 'h', (Address)&histogram,
  391. a77 2
  392.     {OPT_TRUE, 'z', (Address)&useSelect,
  393.         "Make Master use select with 1 client"},
  394. d93 1
  395. a93 1
  396.     Io_Stream outStream;
  397. d97 1
  398. a97 1
  399.     Opt_Parse(&argc, argv, numOptions, optionArray);
  400. d99 1
  401. a99 1
  402.     Io_PrintStream(io_StdErr, "Master: %s [-xfpoh] -M numSlaves\n",
  403. d101 3
  404. a103 3
  405.     Io_PrintStream(io_StdErr, "Slave: %s [-xfpoh] -S\n", argv[0]);
  406.     Opt_PrintUsage(argv[0], numOptions, optionArray);
  407.     Proc_Exit(1);
  408. d105 3
  409. d125 4
  410. a128 13
  411.     if (flushCache) {
  412.     int numLockedBlocks = 0;
  413.     Fs_Command(FS_EMPTY_CACHE, sizeof(int), &numLockedBlocks);
  414.         if (numLockedBlocks > 0) {
  415.             Io_PrintStream(io_StdErr, "Flush found %d locked blocks left\n",
  416.                                       numLockedBlocks);
  417.         }
  418.     }
  419.     outStream = Io_Open(outFile, "w+");
  420.     if (outStream == (Io_Stream)NULL) {
  421.     Io_PrintStream(io_StdErr, "\"%s\": ", outFile);
  422.     Stat_PrintMsg(status, "Can't open");
  423.     Proc_Exit(status);
  424. d133 1
  425. a133 1
  426.     Io_PrintStream(outStream, "%s ", argv[0]);
  427. d135 1
  428. a135 1
  429.     Io_PrintStream(outStream, "-x ");
  430. d138 1
  431. a138 4
  432.     Io_PrintStream(outStream, "-h ");
  433.     }
  434.     if (flushCache) {
  435.     Io_PrintStream(outStream, "-f ");
  436. d141 1
  437. a141 1
  438.     Io_PrintStream(outStream, "-x ");
  439. d144 1
  440. a144 1
  441.     Io_PrintStream(outStream, "%s ", argv[i]);
  442. d146 1
  443. a146 1
  444.     Io_PrintStream(outStream, "\n");
  445. d163 1
  446. a163 1
  447.     Proc_Exit(status);
  448. d168 1
  449. a168 1
  450.     Proc_Exit(status);
  451. d173 1
  452. a173 1
  453.     Proc_Exit(status);
  454. d179 1
  455. a179 1
  456.     Proc_Exit(status);
  457. d183 1
  458. a183 5
  459.         status = Proc_Fork(TRUE, &child);
  460.         if (status != PROC_CHILD_PROC && status != SUCCESS) {
  461.         Stat_PrintMsg(status, "Fork failed");
  462.         Proc_Exit(status);
  463.         }
  464. d185 1
  465. a185 1
  466.     if (read) {
  467. d188 1
  468. a188 1
  469.     if (write) {
  470. d191 1
  471. a191 1
  472.     if (ioctl) {
  473. d195 2
  474. a196 2
  475.         if (status != PROC_CHILD_PROC) {
  476.         status = Proc_Wait(0, NULL, TRUE, NULL, NULL, NULL, NULL, &usage);
  477. d198 1
  478. a198 1
  479.         Proc_Exit(SUCCESS);
  480. d207 2
  481. a208 2
  482.     Io_PrintStream(io_StdOut, "Slave: ");
  483.     PrintTimes(io_StdOut, &usage, &endTime);
  484. d218 1
  485. a218 1
  486.     Io_PrintStream(outStream, "C: ");
  487. d242 2
  488. a243 2
  489.     Io_PrintStream(io_StdOut, "Master: ");
  490.     PrintTimes(io_StdOut, &usage, &endTime);
  491. d251 1
  492. a251 1
  493.     Io_PrintStream(outStream, "S: ");
  494. d268 1
  495. a268 1
  496.         Io_PrintStream(io_StdOut, "%d.%06d seconds service delay\n",
  497. d272 1
  498. a272 2
  499.     Io_Flush(outStream);
  500.     Proc_Exit(status);
  501. @
  502.  
  503.  
  504. 1.1
  505. log
  506. @Initial revision
  507. @
  508. text
  509. @d38 1
  510. d64 2
  511. d96 1
  512. a96 1
  513.     int i;
  514. d273 13
  515. @
  516.